import Md5 from 'crypto-js/md5.js';
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min.js';

export function MD5Encrypt(text: string) {
	return Md5(text).toString().toUpperCase();
}

export function RSAEncrypt(text: string, publicKey: string) {
	if (text.length > 50) {
		text = text.substring(0, 50);
	}
	const encryptor = new JSEncrypt();
	encryptor.setPublicKey(publicKey);
	return encryptor.encrypt(text);
}

export function RSADecrypt(text: string, privateKey: string) {
	const encryptor = new JSEncrypt();
	encryptor.setPrivateKey(privateKey);
	return encryptor.decrypt(text);
}
